# Maintainer: Feng Shu <tumashu@163.com>

_realname=liberime
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.0.6
pkgrel=1
pkgdesc="An emacs dynamic module provide librime bindings for emacs (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/merrickluo/liberime"
license=('GPL3')
depends=("${MINGW_PACKAGE_PREFIX}-librime")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc")
# checkdepends=("${MINGW_PACKAGE_PREFIX}-gtest")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/merrickluo/liberime/archive/v${pkgver}.tar.gz")
sha256sums=('52dd3e000402c3a5476755de053c097cd7b7a2bd4a2134d6019559629b508ebb')

prepare() {
   cd "${_realname}-${pkgver}"
}

build() {
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ${extra_config} \
    "../${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  install -Dm644 liberime-core.dll ${pkgdir}${MINGW_PREFIX}/bin/liberime-core.dll
  install -Dm644 liberime-core.dll.a ${pkgdir}${MINGW_PREFIX}/lib/liberime-core.dll.a
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/README.org ${pkgdir}${MINGW_PREFIX}/share/liberime/README.org
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/liberime.el ${pkgdir}${MINGW_PREFIX}/share/emacs/site-lisp/liberime.el
}
